package com.ruoyi.course.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.course.domain.LabCourseAdjust;
import com.ruoyi.course.service.ILabCourseAdjustService;

/**
 * 调课管理Controller
 * 
 * @author jun.wang
 * @date 2022-04-10
 */
@RestController
@RequestMapping("/course/adjust")
public class LabCourseAdjustController extends BaseController {
	@Autowired
	private ILabCourseAdjustService labCourseAdjustService;

	/**
	 * 查询调课管理列表
	 */
	@PreAuthorize("@ss.hasPermi('course:adjust:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabCourseAdjust labCourseAdjust) {
		startPage();
		labCourseAdjust.setCreateBy(SecurityUtils.getUsername());
		List<LabCourseAdjust> list = labCourseAdjustService.selectLabCourseAdjustList(labCourseAdjust);
		return getDataTable(list);
	}

	/**
	 * 导出调课管理列表
	 */
	// @PreAuthorize("@ss.hasPermi('course:adjust:export')")
	/*
	 * @Log(title = "调课管理", businessType = BusinessType.EXPORT)
	 * 
	 * @GetMapping("/export") public AjaxResult export(LabCourseAdjust
	 * labCourseAdjust) { List<LabCourseAdjust> list =
	 * labCourseAdjustService.selectLabCourseAdjustList(labCourseAdjust);
	 * ExcelUtil<LabCourseAdjust> util = new
	 * ExcelUtil<LabCourseAdjust>(LabCourseAdjust.class); return
	 * util.exportExcel(list, "adjust"); }
	 */

	/**
	 * 获取调课管理详细信息
	 */
	@PreAuthorize("@ss.hasPermi('course:adjust:query')")
	@GetMapping(value = "/{instanceId}")
	public AjaxResult getInfo(@PathVariable("instanceId") Long instanceId) {
		return AjaxResult.success(labCourseAdjustService.selectLabCourseAdjustById(instanceId));
	}

	/**
	 * 新增调课管理
	 */
	@PreAuthorize("@ss.hasPermi('course:adjust:edit')")
	@Log(title = "调课管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabCourseAdjust labCourseAdjust) {
		labCourseAdjustService.insertLabCourseAdjust(labCourseAdjust);
		return AjaxResult.success(labCourseAdjust);
	}

	/**
	 * 调课提交
	 */
	@PreAuthorize("@ss.hasPermi('course:adjust:edit')")
	@Log(title = "调课管理提交流程", businessType = BusinessType.INSERT)
	@PostMapping("/submit")
	public AjaxResult submit(@RequestBody LabCourseAdjust labCourseAdjust) {
		labCourseAdjustService.submitLabApplyOccupation(labCourseAdjust);
		return AjaxResult.success(labCourseAdjust.getInstanceId());
	}

	/**
	 * 修改调课管理
	 */
	@PreAuthorize("@ss.hasPermi('course:adjust:edit')")
	@Log(title = "调课管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabCourseAdjust labCourseAdjust) {
		labCourseAdjustService.updateLabCourseAdjust(labCourseAdjust);
		return AjaxResult.success(labCourseAdjust);
	}

	/**
	 * 删除调课管理
	 */
	@PreAuthorize("@ss.hasPermi('course:adjust:edit')")
	@Log(title = "调课管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instanceIds}")
	public AjaxResult remove(@PathVariable Long[] instanceIds) {
		return toAjax(labCourseAdjustService.deleteLabCourseAdjustByIds(instanceIds));
	}
}
